package com.tucanstubs.android_wheresmystuff.items;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/**
 * This class represents a generic Item. It is abstract because we will never make a generic Item, only 
 * lost items and found items. It defines all the relevant fields for an item including, name, description
 * location, reward, dateEntered, and a boolean indicating whether the Item is matched up or not.
 * @author team 37
 * @version 1.0 2/25/2012
 * 
 *
 */
public abstract class Item {
	private String name;
	private String description;
	private double[] location;
	private boolean matchedUp;
	private Date dateEntered;
	private int id;
	/**
	 * Constructor for Item. Sets all relevant fields to the inputed parameters.
	 * @param name
	 * @param description
	 * @param location
	 * @param dateEntered
	 * @param reward
	 */
	public Item(String name, String description, double[] location, Date dateEntered,int id){
		this.name=name;
		this.description=description;
		this.location=location;
		this.dateEntered=dateEntered;
		this.matchedUp=false;
		this.id = id;
	}


	/**
	 * Getter for Name
	 * @return item's name
	 */
	public String getName() {
		return name;
	}


	/**
	 * Setter for name
	 * @param name item's new name
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * Getter for description
	 * @return item's description
	 */
	public String getDescription() {
		return description;
	}


	/**
	 * Setter for description
	 * @param description item's new description
	 */
	public void setDescription(String description) {
		this.description = description;
	}


	/**
	 * Getter for location
	 * @return item's location
	 */
	public double[] getLocation() {
		return location;
	}


	/**
	 * Setter for location
	 * @param location item's new location
	 */
	public void setLocation(double[] location) {
		this.location = location;
	}


	/**
	 * Determines whether the item is matched up
	 * @return boolean indicating whether the item is matched up
	 */
	public boolean isMatchedUp() {
		return matchedUp;
	}


	/**
	 * Setter for matchedUp
	 * @param matchedUp item's new matchedUp
	 */
	public void setMatchedUp(boolean matchedUp) {
		this.matchedUp = matchedUp;
	}




	/**
	 * Getter for dateEntered
	 * @return item's date entered
	 */
	public Date getDateEntered() {
		return dateEntered;
	}


	/**
	 * Setter for dateEntered
	 * @param dateEntered the item's new dateEntered
	 */
	public void setDateEntered(Date dateEntered) {
		this.dateEntered = dateEntered;
	}
	
	/**
	 * Getter for the Item's ID number
	 * @return Item's id
	 */
	public int getId(){
		return this.id;
	}
	
	/**
	 * Return a string representation of the item
	 * @return items name
	 */
	public String toString(){
		return name+" "+id;
	}
	
	/**
	 * Return a hashcode of the item
	 * @return the hashcode of the item
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dateEntered == null) ? 0 : dateEntered.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + id;
		result = prime * result + Arrays.hashCode(location);
		result = prime * result + (matchedUp ? 1231 : 1237);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}


	/**
	 * Overrides the equals method
	 * @param Object obj the object to compare with
	 * @return a boolean for whether the item is equal to the given item
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Item other = (Item) obj;
		if (dateEntered == null) {
			if (other.dateEntered != null)
				return false;
		} 
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (id != other.id)
			return false;
		if (!Arrays.equals(location, other.location))
			return false;
		if (matchedUp != other.matchedUp)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}


	/**
	 * Returns an ArrayList of the item's information
	 * @return list of item information
	 */
	public ArrayList<String> toList(){
		ArrayList<String> list = new ArrayList<String>();
		list.add("Name: " + name);
		list.add("Description: " + description);
		list.add("Location: " + location[0] + ", " + location[1]);
		list.add("Date entered: " + dateEntered);
		list.add(matchedUp ? "Claimed" : "Not Claimed");
		return list;
	}
	
	
	
}
